#import "DDFSItem.h"
CGFloat const JTWFSItemHEIGHT = 50;
@interface DDFSItem()
@property (nonatomic, strong) DDImageView *IMG;
@property (nonatomic, strong) CCLabel *titleLBL;
@property (nonatomic, strong) DDImageView *selectIMG;
@property (nonatomic, strong) UIView *line;
@end
@implementation DDFSItem
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.line.hidden = NO;
        self.selectIMG.imageName = @"unselect";
    }
    return self;
}
- (DDImageView *)IMG
{
    if (!_IMG)
    {
        _IMG = [[DDImageView alloc] init];
        [self addSubview:_IMG];
        _IMG.c_left.equal(self).with.coffset(GAP);
        _IMG.c_centerY.equal(self);
        _IMG.c_size.equal(CGSizeMake(JTWFSItemHEIGHT - GAP * 1.5, JTWFSItemHEIGHT - GAP * 1.5));
    }
    return _IMG;
}
- (CCLabel *)titleLBL
{
    if (!_titleLBL)
    {
        _titleLBL = [[CCLabel alloc] init];
        _titleLBL.font = FONT(UIFontWeightRegular, 15);
        _titleLBL.textColor = TEXT_BLACK_COLOR;
        [self addSubview:_titleLBL];
        _titleLBL.c_left.equal(self.IMG.c_right).with.coffset(GAP);
        _titleLBL.c_centerY.equal(self);
    }
    return _titleLBL;
}
- (DDImageView *)selectIMG
{
    if (!_selectIMG)
    {
        _selectIMG = [[DDImageView alloc] initWithFrame:CGRectMake(0, 0, JTWFSItemHEIGHT / 3.0, JTWFSItemHEIGHT / 3.0)];
        _selectIMG.layer.cornerRadius = _selectIMG.bounds.size.height / 2.0;
        _selectIMG.layer.masksToBounds = YES;
        [self addSubview:_selectIMG];
        _selectIMG.c_right.equal(self).with.coffset(-GAP);
        _selectIMG.c_centerY.equal(self);
        _selectIMG.c_size.equal(self.selectIMG.bounds.size);
    }
    return _selectIMG;
}
- (UIView *)line
{
    if (!_line)
    {
        _line = [[UIView alloc] init];
        _line.backgroundColor = CELL_LINE_COLOR;
        [self addSubview:_line];
        _line.c_left.equal(self).with.coffset(GAP);
        _line.c_right.equal(self).with.coffset(-GAP);
        _line.c_bottom.equal(self);
        _line.c_height.equal(1.0);
    }
    return _line;
}
DDFSItemManager fsItemManager()
{
    DDFSItemManager manager =
    {
        _getPara,
        _setPara
    };
    return manager;
};
static DDFSModelPara _para;
static DDFSModelPara _getPara()
{
    return _para;
}
static void _setPara(DDFSItem *view, DDFSModelPara para)
{
    _para = para;
    view.titleLBL.text = _para.name;
    NSString *header = helpermanger().getPara().serviceHeader;
    NSString *urlString = ([_para.icon containsString:@"http://120.79.136.107"])?_para.icon:[NSString stringWithFormat:@"%@%@",header,_para.icon];
    NSURL *url = [NSURL URLWithString:urlString];
    view.IMG.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
}
- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];
    self.selectIMG.backgroundColor = (selected)?helpermanger().getPara().color:[UIColor clearColor];
    self.selectIMG.imageName = (selected)?@"selected":@"unselect";
}
@end
